import count from '@dfeidao/atom-nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { systemid } from '../../atom/config';
interface Message {
	filter: {
		attr_name: string
		page_no: number
	};
}
interface dd {
	v?: string;
}
// 自定义属性


export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	// todo查询
	const { exec, prepare } = query(action_id, session_id, systemid);
	prepare('user_defined_attribute', ['_id', 'productid', 'attr_no', 'attr_name', 'is_stop'], { 'attr_name': { $like: '%' + msg.filter.attr_name + '%' } }, 3, msg.filter.page_no, [], []);

	const [rs] = await exec();
	rs.forEach((v: dd) => {
		v.v = JSON.stringify(v);
	});

	const { exec: ex, prepare: p } = count(action_id, session_id, systemid);
	p('user_defined_attribute', { 'attr_name': { $like: '%' + msg.filter.attr_name + '%' } });
	const [c] = await ex();


	log(`Service end`);
	return { rs, c };
}
